package site.potatoblog.threadpool.manager.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.web.bind.annotation.*;
import site.potatoblog.threadpool.manager.core.DynamicThreadPool;
import site.potatoblog.threadpool.manager.service.ThreadPoolMangerService;
import site.potatoblog.threadpool.manager.util.Response;
import site.potatoblog.threadpool.manager.vo.ThreadPoolArgs;


@ConditionalOnBean(DynamicThreadPool.class)
@RestController
@RequestMapping("/threadpool")
public class ThreadPoolManagerController {
    @Autowired
    private ThreadPoolMangerService threadPoolMangerService;

    @GetMapping("/manager")
    public Response getAllThreadPoolArgs(){
        return Response.ok("ok",threadPoolMangerService.getAllThreadPoolArgs());
    }

    @GetMapping("/detail/{name}")
    public Response getDetails(@PathVariable String name){
        return Response.ok("ok",threadPoolMangerService.getThreadPoolDetailByName(name));
    }

    @PostMapping("/manager")
    public Response updateThreadPool(@RequestBody ThreadPoolArgs threadPoolArgs){
        if(threadPoolMangerService.updateThreadPool(threadPoolArgs)){
            return Response.error("参数设置失败");
        }
        return Response.ok("参数设置成功");
    }

}
